/**   
* @Title: LittleUtils.java 
* @Package com.esun.util 
* @Description: TODO(用一句话描述该文件做什么) 
* @author Miko baoz@500wan.com   
* @date 2011-1-14 下午04:05:22  
*/
package com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk;

import java.util.ArrayList;

import com.esun.util.log.EDebug;

/** 
 * @ClassName: LittleUtils 
 * @Description: TODO(小工具类，自写各种小工具) 
 * @author Miko baoz@500wan.com
 * @date 2011-1-14 下午04:05:22 
 *  
 */
public class LittleUtils {
    
    /** 
    * @Title: getTotalLineCount 
    * @Description: TODO(得到总共的显示行数) 
    * @param dataCount 数据总量
    * @param lineSize 每行容量
    * @return int 总共行数
    */
    public static int getTotalLineCount(int dataCount ,int lineSize){
        
        return (dataCount + lineSize - 1)/lineSize;
    }
    
    
    /** 
    * @Title: getAlFromStrings 
    * @Description: TODO(将一维数组形式的二维数组拆分成字符串数组类型的Arraylist) 
    * @param strReturn 一维数组形式的二维数组
    * @return ArrayList<String[]>   拆分成字符串数组类型的Arraylist
    */
    public static ArrayList<String[]> getAlFromStrings(String[] strReturn){
        
        ArrayList<String[]> al = new ArrayList<String[]>();

        // 记录第一位不为空的标志位
        int j = 0;
        for (int i = 0; i < strReturn.length; i++) {
            if (!strReturn[i].equals(DataShare.NULLMARK)) {
                j = i;
                break;
            }
        }
        String collNum = strReturn[j+1];

        for (int k = j + 2; k < strReturn.length; k += Integer.parseInt(collNum)) {
            String[] coll = new String[Integer.parseInt(collNum)];
            for (int i = 0; i < Integer.parseInt(collNum); i++) {
                coll[i] = strReturn[k + i];
            }
            al.add(coll);
        }
        return al;
    }
    
    public static String[] splitFromCode(String str, String code){
        
        StringBuilder sb = new StringBuilder();
        ArrayList<String> al = new ArrayList<String>();
        sb.append(str);
        
        while(str.contains(code)){
            String temp = sb.substring(0,sb.indexOf(code));
            al.add(temp);
            str = sb.delete(0, sb.indexOf(code) + 1).toString();
            
            EDebug.o("Rest str is : " + str);
            
        }
        al.add(sb.toString());
        
        String[] strReturn = new String[al.size()];
        for(int i=0;i<al.size();i++){
            strReturn[i] = al.get(i);
        }
        
        return strReturn;
    }
    

}
